<script type="text/html" template lay-done="layui.data.sendParams(d.params)">
  <div class="layui-form" lay-filter="form_online">
    <div class="layui-form-item">
      <label class="layui-form-label">肓盒名称</label>
      <div class="layui-form-mid layui-word-aux">
        <input type="text" class="layui-input" lay-verify="required" name="name"
               value="{{d.params.name || ''}}">
      </div>
      <div class="layui-input-inline">
        <input type="checkbox" name="show_left_count" lay-skin="switch" lay-text="显示实时库存|不显示实时库存"
               {{ (!d.params.configs.show_left_count || d.params.configs.show_left_count==1)?'checked':''}}>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">销售价格</label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" lay-verify="required" name="display_price"
                 value="{{d.params.display_price || ''}}">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">限购数量</label>
        <div class="layui-input-inline" style="width: 50px">
          <input type="text" class="layui-input" lay-verify="required" name="buy_limit"
                 value="{{d.params.buy_limit || -1}}">
        </div>
        <div class="layui-input-inline layui-word-aux layui-form-mid">
          -1代表不限制
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">排序</label>
      <div class="layui-input-inline" style="width: 80px">
        <input type="number" class="layui-input" lay-verify="required" name="sequence" placeholder="排序"
               value="{{d.params.sequence || 0}}">
      </div>
      <div class="layui-inline layui-form-mid">数字越大，排序越靠前</div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">开始时间</label>
        <div class="layui-input-inline">
          <input type="text" id="start_time" class="layui-input" name="start_time" placeholder="默认上架时开始"
                 autocomplete="off" value="{{d.params.start_time || ''}}">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-inline">
          <input type="text" id="end_time" class="layui-input" name="end_time" placeholder="默认下架时结束"
                 autocomplete="off" value="{{d.params.end_time || ''}}">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">发行方</label>
      <div class="layui-input-inline" style="width: 200px">
        <input name="issuer" type="text" class="layui-input" value="{{d.params.issuer || ''}}"/>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label form-required">商品图片</label>
      <div class="layui-input-block">
        <div id="product_images"></div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">商品详情</label>
      <div class="layui-input-inline" style="width: 600px">
        <div id="description">
          {{d.params.description || ''}}
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-footer">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
          <input type="button" lay-submit lay-filter="submit_basic" value="确认" class="layui-btn">
        </div>
      </div>
    </div>
  </div>
</script>
<script>
  layui.data.sendParams = function (obj) {
    // console.log(obj)
    layui.use(['fox_upload', 'wangEditor'], function () {
      let fox_upload = layui.fox_upload
        , form = layui.form
        , admin = layui.admin
        , laydate = layui.laydate
        , editor = layui.wangEditor

      form.render()

      //日历初始化
      laydate.render({
        elem: '#start_time'
        , type: 'datetime'
        , value: obj.start_time
      });
      laydate.render({
        elem: '#end_time'
        , type: 'datetime'
        , value: obj.end_time
      });

      //上传控件初始化
      fox_upload.render({
        elem: '#product_images'
        , url: 'agent-admin/products/image'
        , headers: {
          Authorization: admin.getAccessToken('Bearer')
        }
        , text: '点击上传'
        , name: 'logo_url'
        , value: obj.logo_url
      });

      //编辑器
      editor.render({
        elem: "#description"
        , height: 500
        , name: 'description'
        , url: 'editor/images'
      });
    })
  }
</script>
